<?php

namespace App\Admin\Controllers\Sys;

use App\Models\Subscribe\Price;
use App\Models\Sys\Task;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use Illuminate\Http\Request;

class PriceController extends Controller
{
    use ModelForm;

    public $header = '家长订阅币规则设置';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('description');


            $box1 = new Widgets\Box('家长订阅币规则设置',$this->grid()->render());
            $content->row($box1->solid()->style('primary'));
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('description');

            $content->body($this->form()->edit($id));


        });
    }

    protected function grid()
    {
        return Admin::grid(Price::class, function (Grid $grid) {
            $grid->id('ID')->sortable();
            $grid->monthNum('家长订阅')->display(function ($v){
                return $v . '月';
            });
            $grid->gold('积分')->editable();
            $grid->expe('经验')->editable();

            $grid->actions(function(Grid\Displayers\Actions $actions){
                $actions->disableDelete();
                $actions->disableView();
            });

            $grid->disableCreateButton();
            $grid->disableFilter();
            $grid->disableRowSelector();
            $grid->disablePagination();
        });
    }

    protected function form()
    {
        return Admin::form(Price::class, function (Form $form) {

            $form->display('id', 'ID');
            $form->display('monthNum', '月份');
            $form->number('gold','积分')->rules('required|integer');
            $form->number('expe','经验值')->rules('required|integer');

            $form->tools(function(Form\Tools $tools){
                $tools->disableView();
                $tools->disableDelete();
            });

            $form->footer(function ($footer){
                $footer->disableViewCheck();
                $footer->disableEditingCheck();
            });

        });
    }


}
